package desktop.lan.cooperate;

import pulpcore.Stage;
import pulpcore.scene.Scene2D;
import desktop.conf.key.KeyConfDefault;
import desktop.core.playfield.PlayFieldModel;
import desktop.core.playfield.PlayFieldViewDoubleBar;
import desktop.lan.remote.key.KeyRemote;
import desktop.lan.remote.key.KeyRemoteClient;
import desktop.lan.remote.key.KeyRemoteImpl;

/**
 * 对于运行该场景的主机，PlayField是Server，而该PlayField调用的Controller是client;
 * 
 * @author wuyang
 */
public class LanCooperateServerScene extends Scene2D {
	private PlayFieldModel playFieldModel = new PlayFieldModel();
	private PlayFieldViewDoubleBar doubleBarPlayFieldView;
	private LanCooperateServer lanCooperateServer;
	private KeyRemoteImpl keyRemoteImpl = null;
	private KeyRemote keyRemoteRight = null;

	@Override
	public void load() {
		lanCooperateServer = new LanCooperateServer(this.playFieldModel);
		new Thread(lanCooperateServer).start();
		this.keyRemoteImpl = lanCooperateServer.getKeyRemoteImpl();

		KeyRemoteClient keyRemoteClient = new KeyRemoteClient("KeyRemoteRight");
		this.keyRemoteRight = keyRemoteClient.getRemoteInterface();

		// doubleBarPlayFieldView = new PlayFieldViewDoubleBar(0, 0, Stage
		// .getWidth(), Stage.getHeight(), this.playFieldModel,
		// new BarControllerByKeyboard(new KeyConfDefault()),
		// new BarControllerByRemote(new KeyConfDefault(),
		// this.keyRemoteRight));
		// this.add(doubleBarPlayFieldView);
	}

	@Override
	public void update(int elapsedTime) {
		this.keyRemoteImpl.searchKeyPressed();
	}

}